Skip to content

Conversation

louisunlimited
Copy link

Adds some doc on usage with adding enum help texts. I also asked claude to add some helpful tips in there, but can remove them if it's too much.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

}
```

### Tips for Effective Enum Descriptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets cut this section

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!


When your argument or option uses an enum type, you can provide detailed descriptions for each enum value that will appear in the help screen. This is especially useful when the enum cases represent complex concepts that benefit from explanation.

### Basic Enum Value Descriptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use just one enum throughout this documentation, I think output format is a good example

@bhab20476-prog
Copy link

bhab20476-prog commented Oct 4, 2025 via email

@louisunlimited
Copy link
Author

Implemented feedback, lmk what else I can do!

@bhab20476-prog
Copy link

bhab20476-prog commented Oct 5, 2025 via email

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on the documentation, @louisunlimited! I've requested some changes below.

### Customizing Help for Arguments

For more control over the help text, pass an ``ArgumentHelp`` instance instead of a string literal. The `ArgumentHelp` type can include an abstract (which is what the string literal becomes), a discussion, a value name to use in the usage string, and a visibility level for that argument.
For more control over the help text, pass an `ArgumentHelp` instance instead of a string literal. The `ArgumentHelp` type can include an abstract (which is what the string literal becomes), a discussion, a value name to use in the usage string, and a visibility level for that argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are removing links to the documentation (the double backticks) – can you revert that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Comment on lines 227 to 258
### Working with Raw Values

For enums with custom raw values, the descriptions work with the raw value representation. Here's the same `OutputFormat` enum with custom raw values:

```swift
enum OutputFormat: String, CaseIterable, ExpressibleByArgument {
case json = "json"
case yaml = "yml"
case xml = "xml"
case csv = "csv"

var defaultValueDescription: String {
switch self {
case .json:
return "JavaScript Object Notation format"
case .yaml:
return "YAML Ain't Markup Language format"
case .xml:
return "eXtensible Markup Language format"
case .csv:
return "Comma-Separated Values format"
}
}
}

struct DataExporter: ParsableCommand {
@Option(help: "Select output format")
var format: OutputFormat = .json
}
```

In this example, users would specify `--format yml` to get YAML output, but the help screen still shows the descriptive text.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content in this section is covered above, under the "Deriving Possible Values" header. Could you look at improving that section if it doesn't cover what you'd like to see?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think you're right, I was trying to cover all the cases and make this section be a no brainer read through. It can be removed.

-h, --help Show help information.
```

### Array Options with Enum Descriptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this section needs to exist, since the customization / help screen display is the same whether a type is included a single option or as an array. The first sentence ("The same enum value descriptions...") could be included after the last example, if you'd like.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll nuke this section.

Comment on lines 153 to 157
## Providing Descriptions for Individual Enum Values

When your argument or option uses an enum type, you can provide detailed descriptions for each enum value that will appear in the help screen. This is especially useful when the enum cases represent complex concepts that benefit from explanation.

### Basic Enum Value Descriptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the other two sub-sections here will be eliminated, can you just use a single header for this section about customizing the value descriptions? This should use a level 4 header (i.e. ####) since it's under the "Enumerating Possible Values" section.

@louisunlimited
Copy link
Author

@natecook1000 just did all the changes! Let me know what else you need :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an example on how to provide additional help for each item in an enum

4 participants